/**
  ******************************************************************************
  * @file           : sensor.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SENSOR_H
#define __SENSOR_H

#include <stdint.h>

#define SENSOR_UART                     UART4
#define SENSOR_UART_BAUDRATE            115200
#define SENSOR_UART_IRQn                UART4_IRQn
#define SENSOR_UART_IRQHandler          UART4_IRQHandler
#define SENSOR_UART_EnableClock()       LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART4)
#define SENSOR_UART_IO_EnableClock()    LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA)

#define SENSOR_UART_txDMA               DMA1
#define SENSOR_UART_txDMA_STREAM        LL_DMA_STREAM_4
#define SENSOR_UART_txDMA_CHANNEL       LL_DMA_CHANNEL_4
#define SENSOR_UART_txDMA_IRQn          DMA1_Stream4_IRQn
#define SENSOR_UART_txDMA_IRQHandler    DMA1_Stream4_IRQHandler

#define SENSOR_OUTTIMER                 TIM7
#define SENSOR_OUTTIMER_IRQn            TIM7_IRQn
#define SENSOR_OUTTIMER_IRQHandler      TIM7_IRQHandler
#define SENSOR_OUTTIMER_EnableClock()   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM7)

#define SENSOR_GPIO_Port                GPIOA
#define SENSOR_GPIO_LL_AF               LL_GPIO_AF_8
#define SENSOR_TX_LL_Pin                LL_GPIO_PIN_0
#define SENSOR_RX_LL_Pin                LL_GPIO_PIN_1

#define SENSOR_RECV_QUE_LENGTH          3
#define SENSOR_RECV_QUE_ITEMSIZE        sizeof(Sensor_BufStru)

#define SENSOR_FRAME_BUFLEN             28

#define SENSOR_RECV_TIMEOUT             7
#define SENSOR_WAD_FILTER_WINDOW        10         /* 滤波窗口,越大越平滑越滞后,越小越波动越实时 */
#define SENSOR_WAD_ERRCNT_MAX           10         /* 错误最大计数 */

typedef struct _Sensor_WadFilterStru
{
  int8_t  cnt;
  int32_t buf[SENSOR_WAD_FILTER_WINDOW];
}Sensor_WadFilterStru;

typedef struct _Sensor_BufStru
{
  uint8_t dummy1;
  uint8_t dummy2;
  uint8_t dummy3;
  uint8_t cnt;
  uint8_t buf[SENSOR_FRAME_BUFLEN];
}Sensor_BufStru;

extern void sensor_uart_init(void);
extern void sensor_send_str(const char *buf);
extern void sensor_send_buf(const uint8_t *buf, uint32_t len);
extern void sensor_dma_send_buf(const uint8_t *buf, uint16_t len);

#endif /* __SENSOR_H */
